#include "inputdlg.h"
#include <QtWidgets>
#include <QtGui>


InputDlg::InputDlg(QWidget *parent)
    : QDialog(parent)
    //, ui(new Ui::InputDlg)
{
    setupUi(this);
    setWindowTitle(tr("Input Dialog"));

    connect(nameButton, SIGNAL(clicked()), this, SLOT(slotName()));
    connect(sexButton, SIGNAL(clicked()), this, SLOT(slotSex()));
    connect(ageButton, SIGNAL(clicked()), this, SLOT(slotAge()));
    connect(statureButton, SIGNAL(clicked()), this, SLOT(slotStature()));
}

InputDlg::~InputDlg()
{
    //delete ui;
}

void InputDlg::slotName()
{
    bool ok;
    QString name=QInputDialog::getText(this, tr("User Name"),
                                       tr("Please input new name:"),QLineEdit::Normal, nameLabel->text(),&ok);
    if(ok && !name.isEmpty())
        nameLabel->setText(name);

}

void InputDlg::slotAge()
{
    bool ok;
    int age=QInputDialog::getInt(this, tr("User Age"),
                                 tr("Please input age:"),ageLabel->text().toInt(),0,150,1,&ok);
    if(ok)
        ageLabel->setText(QString(tr("%1")).arg(age));

}

void InputDlg::slotSex()
{

    QStringList list;
    list<<tr("male")<<tr("female");
    bool ok;
    QString sex=QInputDialog::getItem(this, tr("sex"),
                                      tr("Please select sex:"),list,0,false,&ok);
    if(ok)
        sexLabel->setText(sex);
}

void InputDlg::slotStature()
{
    bool ok;
    double d=QInputDialog::getDouble(this, tr("stature"),
                                     tr("Please input stature:"),0,175.00,230.00,1,&ok);
    if(ok)
        statureLabel->setText(QString(tr("%1")).arg(d));

}
